using System;

using Sunyi.Project.WebPoint.Common;
using Sunyi.Project.WebPoint.DataAccessController;

using Sunyi.Project.WebPoint.DataAccess;
using Sunyi.Project.WebPoint.DataContract;

namespace Sunyi.Project.WebPoint.DataAccessController
{
    public partial class RoleDaoController : ProvisioningDaoController<Role, RoleDao>
    {
        public override void Insert(Role role)
        {
            if (role.Id == Guid.Empty) role.Id = Guid.NewGuid();

            TransactionHelper.ProcessTransaction(() => { dao.Insert(role); dao.SavePermissions(role); });
        }

        public void Save(Role role)
        {
            TransactionHelper.ProcessTransaction(() => { dao.Update(role); dao.SavePermissions(role); CacheProvider.Instance.Remove<Role>(role.Id); });
        }

        protected override void FillEntity(Role entity) { if (entity != null) { dao.FillPermissions(entity); } }
    }
}
